module Final(rst,clk,inc,inc_dec,en0,en1,en2,en3,en4,en5,en6,en7,zoom, R, G, B, vga_h_sync, vga_v_sync, vga_clk, vga_sync, vga_blank);
	input clk,rst;
	
	input inc,inc_dec,zoom;
	
	input en0,en1,en2,en3,en4,en5,en6,en7;
	
	output vga_h_sync,vga_v_sync, vga_clk, vga_sync, vga_blank;
	output [9:0]R;
	output [9:0]G;
	output [9:0]B;
	
	wire color;
	
	reg [9:0] CounterX;
	reg [8:0] CounterY;
	wire CounterXmaxed = (CounterX==767);
	
	always @(posedge clk)
	if(CounterXmaxed)
	  CounterX <= 0;
	else
	  CounterX <= CounterX + 1;
	
	always @(posedge clk)
	if(CounterXmaxed)
		 CounterY <= CounterY + 1;
		 
	reg vga_HS, vga_VS;
	always @(posedge clk)
	begin
	  vga_HS <= (CounterX[9:4]==0);   // active for 16 clocks
	  vga_VS <= (CounterY==0);   // active for 768 clocks
	end
	
	assign vga_h_sync = ~vga_HS;
	assign vga_v_sync = ~vga_VS;
	
	wire Y,equals,graph2;
	wire co0,sg0,co1,sg1,co2,sg2,co3,sg3,co4,sg4,co5,sg5,co6,sg6,co7,sg7;
	wire X1,X2,X3,X4,X5,X6,X7;
	wire ex2,ex3,ex4,ex5,ex6,ex7;
	
	reg [4:0]num0;
	reg sign0;
	reg [4:0]num1;
	reg sign1;
	reg [4:0]num2;
	reg sign2;
	reg [4:0]num3;
	reg sign3;
	reg [4:0]num4;
	reg sign4;
	reg [4:0]num5;
	reg sign5;
	reg [4:0]num6;
	reg sign6;
	reg [4:0]num7;
	reg sign7;
	
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num0<=0;
			sign0<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en0==1'b1)
			begin
				if(num0<9&&sign0==0)
					num0<=num0+1;
				else if(num0>0&&sign0==1)
					num0<=num0-1;
					
				if(num0==0)
					sign0<=0;
			end
			else if(inc_dec==1'b0&&en0==1'b1)
			begin
				if(num0>0&&sign0==0)
					num0<=num0-1;
				else if(num0<9&&sign0==1)
					num0<=num0+1;
				if(num0==0)
					sign0<=1;	
			end	
		end
	end
	
		always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num1<=0;
			sign1<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en1==1'b1)
			begin
				if(num1<9&&sign1==0)
					num1<=num1+1;
				else if(num1>0&&sign1==1)
					num1<=num1-1;
					
				if(num1==0)
					sign1<=0;
			end
			else if(inc_dec==1'b0&&en1==1'b1)
			begin
				if(num1>0&&sign1==0)
					num1<=num1-1;
				else if(num1<9&&sign1==1)
					num1<=num1+1;
				if(num1==0)
					sign1<=1;	
			end	
		end
	end
		always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num2<=0;
			sign2<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en2==1'b1)
			begin
				if(num2<9&&sign2==0)
					num2<=num2+1;
				else if(num2>0&&sign2==1)
					num2<=num2-1;
					
				if(num2==0)
					sign2<=0;
			end
			else if(inc_dec==1'b0&&en2==1'b1)
			begin
				if(num2>0&&sign2==0)
					num2<=num2-1;
				else if(num2<9&&sign2==1)
					num2<=num2+1;
				if(num2==0)
					sign2<=1;	
			end	
		end
	end
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num3<=0;
			sign3<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en3==1'b1)
			begin
				if(num3<9&&sign3==0)
					num3<=num3+1;
				else if(num3>0&&sign3==1)
					num3<=num3-1;
					
				if(num3==0)
					sign3<=0;
			end
			else if(inc_dec==1'b0&&en3==1'b1)
			begin
				if(num3>0&&sign3==0)
					num3<=num3-1;
				else if(num3<9&&sign3==1)
					num3<=num3+1;
				if(num3==0)
					sign3<=1;	
			end	
		end
	end
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num4<=0;
			sign4<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en4==1'b1)
			begin
				if(num4<9&&sign4==0)
					num4<=num4+1;
				else if(num4>0&&sign4==1)
					num4<=num4-1;
					
				if(num4==0)
					sign4<=0;
			end
			else if(inc_dec==1'b0&&en4==1'b1)
			begin
				if(num4>0&&sign4==0)
					num4<=num4-1;
				else if(num4<9&&sign4==1)
					num4<=num4+1;
				if(num4==0)
					sign4<=1;	
			end	
		end
	end
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num5<=0;
			sign5<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en5==1'b1)
			begin
				if(num5<9&&sign5==0)
					num5<=num5+1;
				else if(num5>0&&sign5==1)
					num5<=num5-1;
					
				if(num5==0)
					sign5<=0;
			end
			else if(inc_dec==1'b0&&en5==1'b1)
			begin
				if(num5>0&&sign5==0)
					num5<=num5-1;
				else if(num5<9&&sign5==1)
					num5<=num5+1;
				if(num5==0)
					sign5<=1;	
			end	
		end
	end
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num6<=0;
			sign6<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en6==1'b1)
			begin
				if(num6<9&&sign6==0)
					num6<=num6+1;
				else if(num6>0&&sign6==1)
					num6<=num6-1;
					
				if(num6==0)
					sign6<=0;
			end
			else if(inc_dec==1'b0&&en6==1'b1)
			begin
				if(num6>0&&sign6==0)
					num6<=num6-1;
				else if(num6<9&&sign6==1)
					num6<=num6+1;
				if(num6==0)
					sign6<=1;	
			end	
		end
	end
	always @(negedge inc or negedge rst)
	begin
		if(rst==1'b0)
		begin
			num7<=0;
			sign7<=0;
		end
		else
		begin
			if(inc_dec==1'b1&&en7==1'b1)
			begin
				if(num7<9&&sign7==0)
					num7<=num7+1;
				else if(num7>0&&sign7==1)
					num7<=num7-1;
					
				if(num7==0)
					sign7<=0;
			end
			else if(inc_dec==1'b0&&en7==1'b1)
			begin
				if(num7>0&&sign7==0)
					num7<=num7-1;
				else if(num7<9&&sign7==1)
					num7<=num7+1;
				if(num7==0)
					sign7<=1;	
			end	
		end
	end	
	
	draw vs1(225,100,CounterX, CounterY,15, plane);
	graph g(clk,rst,225,100,CounterX, CounterY,zoom,num0,num1,num2,num3,num4,num5,num6,num7,sign0,sign1,sign2,sign3,sign4,sign5,sign6,sign7,graph2);
	
	draw vs2(350,450, CounterX,CounterY,11,Y);
	draw vs3(357,450, CounterX,CounterY,14,equals);
	
	draw vs4(364, 450, CounterX,CounterY,sign7+12,sg7);
	draw vs5(371,450, CounterX,CounterY,num7,co7);
	draw vs6(378,450, CounterX,CounterY,10,X7);
	draw vs7(384,445, CounterX,CounterY,7,ex7);
	
	draw vs8(391, 450, CounterX,CounterY,sign6+12,sg6);
	draw vs9(398,450, CounterX,CounterY,num6,co6);
	draw vs10(407,450, CounterX,CounterY,10,X6);
	draw vs11(413,445, CounterX,CounterY,6,ex6);
	
	draw vs12(420, 450, CounterX,CounterY,sign5+12,sg5);
	draw vs13(427,450, CounterX,CounterY,num5,co5);
	draw vs14(434,450, CounterX,CounterY,10,X5);
	draw vs15(440,445, CounterX,CounterY,5,ex5);
	
	draw vs16(447, 450, CounterX,CounterY,sign4+12,sg4);
	draw vs17(454,450, CounterX,CounterY,num4,co4);
	draw vs18(461,450, CounterX,CounterY,10,X4);
	draw vs19(467,445, CounterX,CounterY,4,ex4);
	
	draw vs20(474, 450, CounterX,CounterY,sign3+12,sg3);
	draw vs21(481,450, CounterX,CounterY,num3,co3);
	draw vs22(487,450, CounterX,CounterY,10,X3);
	draw vs23(493,445, CounterX,CounterY,3,ex3);
	
	draw vs24(500, 450, CounterX,CounterY,sign2+12,sg2);
	draw vs25(507,450, CounterX,CounterY,num2,co2);
	draw vs26(514,450, CounterX,CounterY,10,X2);
	draw vs27(520,445, CounterX,CounterY,2,ex2);
	
	draw vs28(527, 450, CounterX,CounterY,sign1+12,sg1);
	draw vs29(534,450, CounterX,CounterY,num1,co1);
	draw vs30(541,450, CounterX,CounterY,10,X1);
	
	draw vs31(548, 450, CounterX,CounterY,sign0+12,sg0);
	draw vs32(555,450, CounterX,CounterY,num0,co0);
	
	
	
	
	assign color=co0|sg0|co1|sg1|co2|sg2|co3|sg3|co4|sg4|co5|sg5|co6|sg6|co7|sg7|
					(graph2&&CounterX>=225&&CounterX<=524&&CounterY>=100&&CounterY<=399)|plane|
					X1|X2|X3|X4|X5|X6|X7|
					ex2|ex3|ex4|ex5|ex6|ex7|
					Y|equals;
	
	
	
	assign R[9] = color;
	assign R[8] = color;
	assign R[7] = color;
	assign R[6] = color;
	assign R[5] = color;
	assign R[4] = color;
	assign R[3] = color;
	assign R[2] = color;
	assign R[1] = color;
	assign R[0] = color;
	assign G[9] = color;
	assign G[8] = color;
	assign G[7] = color;
	assign G[6] = color;
	assign G[5] = color;
	assign G[4] = color;
	assign G[3] = color;
	assign G[2] = color;
	assign G[1] = color;
	assign G[0] = color;
	assign B[9] = color;
	assign B[8] = color;
	assign B[7] = color;
	assign B[6] = color;
	assign B[5] = color;
	assign B[4] = color;
	assign B[3] = color;
	assign B[2] = color;
	assign B[1] = color;
	assign B[0] = color;
	
	assign vga_sync = 1'b0;
	assign vga_blank = vga_h_sync & vga_v_sync;
	assign vga_clk = clk;

	
endmodule

module graph(clk,rst,startX,startY,CounterX,CounterY,zoom,num0,num1,num2,num3,num4,num5,num6,num7,sign0,sign1,sign2,sign3,sign4,sign5,sign6,sign7,color);
	
	input clk,rst,zoom;
	input [4:0]num0;
	input [4:0]num1;
	input [4:0]num2;
	input [4:0]num3;
	input [4:0]num4;
	input [4:0]num5;
	input [4:0]num6;
	input [4:0]num7;
	input sign0,sign1,sign2,sign3,sign4,sign5,sign6,sign7;
	input [9:0]startX;
	input [8:0]startY;
	reg [9:0]x[299:0];
	reg [15:0]y[299:0];
	input [9:0]CounterX;
	input [8:0]CounterY;
	output color;
	
	reg [9:0]clkCount;
	reg [9:0]counter;
	
	always @(posedge clk or negedge rst)
	begin
		if(rst==1'b0)
		begin
			counter<=0;
			clkCount<=0;
		end
		else
		begin
			if(counter<300&&clkCount>=100)
			begin
				counter<=counter+1;
				x[counter]<=counter;
				if(zoom==1)
				begin
					if(counter>150)
					begin
						y[counter]<=149
									+((2*sign7-1)*((((counter-150)**7)*num7)/1000000000000))
									+(((2*sign6-1))*((((counter-150)**6)*num6)/10000000000))
									+((2*sign5-1)*((((counter-150)**5)*num5)/100000000))
									+(((2*sign4-1))*((((counter-150)**4)*num4)/1000000))
									+((2*sign3-1)*((((counter-150)**3)*num3)/10000))
									+(((2*sign2-1))*((((counter-150)**2)*num2)/100))
									+(((2*sign1-1)*num1)*(counter-150))
									+(((2*sign0-1)*num0)*100);
					end
					else
					begin
						y[counter]<=149
									-((2*sign7-1)*((((150-counter)**7)*num7)/1000000000000))
									+(((2*sign6-1))*((((150-counter)**6)*num6)/10000000000))
									-((2*sign5-1)*((((150-counter)**5)*num5)/100000000))
									+(((2*sign4-1))*((((150-counter)**4)*num4)/1000000))
									-((2*sign3-1)*((((150-counter)**3)*num3)/10000))
									+(((2*sign2-1))*((((150-counter)**2)*num2)/100))
									-(((2*sign1-1)*num1)*(150-counter))
									+(((2*sign0-1)*num0)*100);
					end
				end
				else
				begin
					if(counter>150)
					begin
						y[counter]<=149
									+((2*sign7-1)*((((counter-150)**7)*num7)/1000000))
									+(((2*sign6-1))*((((counter-150)**6)*num6)/100000))
									+((2*sign5-1)*((((counter-150)**5)*num5)/10000))
									+(((2*sign4-1))*((((counter-150)**4)*num4)/1000))
									+((2*sign3-1)*((((counter-150)**3)*num3)/100))
									+(((2*sign2-1))*((((counter-150)**2)*num2)/10))
									+(((2*sign1-1)*num1)*(counter-150))
									+(((2*sign0-1)*num0)*10);
					end
					else
					begin
						y[counter]<=149
									-((2*sign7-1)*((((150-counter)**7)*num7)/1000000))
									+(((2*sign6-1))*((((150-counter)**6)*num6)/100000))
									-((2*sign5-1)*((((150-counter)**5)*num5)/10000))
									+(((2*sign4-1))*((((150-counter)**4)*num4)/1000))
									-((2*sign3-1)*((((150-counter)**3)*num3)/100))
									+(((2*sign2-1))*((((150-counter)**2)*num2)/10))
									-(((2*sign1-1)*num1)*(150-counter))
									+(((2*sign0-1)*num0)*10);
					end
				end
				clkCount<=0;
			end
			else if(counter<300&&clkCount<100)
				clkCount<=clkCount+1;
			else
				counter<=0;
		end
	end
	
	assign color = (CounterX==startX+(x[0])&&CounterY==startY+(y[0]))|
						(CounterX==startX+(x[1])&&CounterY==startY+(y[1]))|
						(CounterX==startX+(x[2])&&CounterY==startY+(y[2]))|
						(CounterX==startX+(x[3])&&CounterY==startY+(y[3]))|
						(CounterX==startX+(x[4])&&CounterY==startY+(y[4]))|
						(CounterX==startX+(x[5])&&CounterY==startY+(y[5]))|
						(CounterX==startX+(x[6])&&CounterY==startY+(y[6]))|
						(CounterX==startX+(x[7])&&CounterY==startY+(y[7]))|
						(CounterX==startX+(x[8])&&CounterY==startY+(y[8]))|
						(CounterX==startX+(x[9])&&CounterY==startY+(y[9]))|
						(CounterX==startX+(x[10])&&CounterY==startY+(y[10]))|
						(CounterX==startX+(x[11])&&CounterY==startY+(y[11]))|
						(CounterX==startX+(x[12])&&CounterY==startY+(y[12]))|
						(CounterX==startX+(x[13])&&CounterY==startY+(y[13]))|
						(CounterX==startX+(x[14])&&CounterY==startY+(y[14]))|
						(CounterX==startX+(x[15])&&CounterY==startY+(y[15]))|
						(CounterX==startX+(x[16])&&CounterY==startY+(y[16]))|
						(CounterX==startX+(x[17])&&CounterY==startY+(y[17]))|
						(CounterX==startX+(x[18])&&CounterY==startY+(y[18]))|
						(CounterX==startX+(x[19])&&CounterY==startY+(y[19]))|
						(CounterX==startX+(x[20])&&CounterY==startY+(y[20]))|
						(CounterX==startX+(x[21])&&CounterY==startY+(y[21]))|
						(CounterX==startX+(x[22])&&CounterY==startY+(y[22]))|
						(CounterX==startX+(x[23])&&CounterY==startY+(y[23]))|
						(CounterX==startX+(x[24])&&CounterY==startY+(y[24]))|
						(CounterX==startX+(x[25])&&CounterY==startY+(y[25]))|
						(CounterX==startX+(x[26])&&CounterY==startY+(y[26]))|
						(CounterX==startX+(x[27])&&CounterY==startY+(y[27]))|
						(CounterX==startX+(x[28])&&CounterY==startY+(y[28]))|
						(CounterX==startX+(x[29])&&CounterY==startY+(y[29]))|
						(CounterX==startX+(x[30])&&CounterY==startY+(y[30]))|
						(CounterX==startX+(x[31])&&CounterY==startY+(y[31]))|
						(CounterX==startX+(x[32])&&CounterY==startY+(y[32]))|
						(CounterX==startX+(x[33])&&CounterY==startY+(y[33]))|
						(CounterX==startX+(x[34])&&CounterY==startY+(y[34]))|
						(CounterX==startX+(x[35])&&CounterY==startY+(y[35]))|
						(CounterX==startX+(x[36])&&CounterY==startY+(y[36]))|
						(CounterX==startX+(x[37])&&CounterY==startY+(y[37]))|
						(CounterX==startX+(x[38])&&CounterY==startY+(y[38]))|
						(CounterX==startX+(x[39])&&CounterY==startY+(y[39]))|
						(CounterX==startX+(x[40])&&CounterY==startY+(y[40]))|
						(CounterX==startX+(x[41])&&CounterY==startY+(y[41]))|
						(CounterX==startX+(x[42])&&CounterY==startY+(y[42]))|
						(CounterX==startX+(x[43])&&CounterY==startY+(y[43]))|
						(CounterX==startX+(x[44])&&CounterY==startY+(y[44]))|
						(CounterX==startX+(x[45])&&CounterY==startY+(y[45]))|
						(CounterX==startX+(x[46])&&CounterY==startY+(y[46]))|
						(CounterX==startX+(x[47])&&CounterY==startY+(y[47]))|
						(CounterX==startX+(x[48])&&CounterY==startY+(y[48]))|
						(CounterX==startX+(x[49])&&CounterY==startY+(y[49]))|
						(CounterX==startX+(x[50])&&CounterY==startY+(y[50]))|
						(CounterX==startX+(x[51])&&CounterY==startY+(y[51]))|
						(CounterX==startX+(x[52])&&CounterY==startY+(y[52]))|
						(CounterX==startX+(x[53])&&CounterY==startY+(y[53]))|
						(CounterX==startX+(x[54])&&CounterY==startY+(y[54]))|
						(CounterX==startX+(x[55])&&CounterY==startY+(y[55]))|
						(CounterX==startX+(x[56])&&CounterY==startY+(y[56]))|
						(CounterX==startX+(x[57])&&CounterY==startY+(y[57]))|
						(CounterX==startX+(x[58])&&CounterY==startY+(y[58]))|
						(CounterX==startX+(x[59])&&CounterY==startY+(y[59]))|
						(CounterX==startX+(x[60])&&CounterY==startY+(y[60]))|
						(CounterX==startX+(x[61])&&CounterY==startY+(y[61]))|
						(CounterX==startX+(x[62])&&CounterY==startY+(y[62]))|
						(CounterX==startX+(x[63])&&CounterY==startY+(y[63]))|
						(CounterX==startX+(x[64])&&CounterY==startY+(y[64]))|
						(CounterX==startX+(x[65])&&CounterY==startY+(y[65]))|
						(CounterX==startX+(x[66])&&CounterY==startY+(y[66]))|
						(CounterX==startX+(x[67])&&CounterY==startY+(y[67]))|
						(CounterX==startX+(x[68])&&CounterY==startY+(y[68]))|
						(CounterX==startX+(x[69])&&CounterY==startY+(y[69]))|
						(CounterX==startX+(x[70])&&CounterY==startY+(y[70]))|
						(CounterX==startX+(x[71])&&CounterY==startY+(y[71]))|
						(CounterX==startX+(x[72])&&CounterY==startY+(y[72]))|
						(CounterX==startX+(x[73])&&CounterY==startY+(y[73]))|
						(CounterX==startX+(x[74])&&CounterY==startY+(y[74]))|
						(CounterX==startX+(x[75])&&CounterY==startY+(y[75]))|
						(CounterX==startX+(x[76])&&CounterY==startY+(y[76]))|
						(CounterX==startX+(x[77])&&CounterY==startY+(y[77]))|
						(CounterX==startX+(x[78])&&CounterY==startY+(y[78]))|
						(CounterX==startX+(x[79])&&CounterY==startY+(y[79]))|
						(CounterX==startX+(x[80])&&CounterY==startY+(y[80]))|
						(CounterX==startX+(x[81])&&CounterY==startY+(y[81]))|
						(CounterX==startX+(x[82])&&CounterY==startY+(y[82]))|
						(CounterX==startX+(x[83])&&CounterY==startY+(y[83]))|
						(CounterX==startX+(x[84])&&CounterY==startY+(y[84]))|
						(CounterX==startX+(x[85])&&CounterY==startY+(y[85]))|
						(CounterX==startX+(x[86])&&CounterY==startY+(y[86]))|
						(CounterX==startX+(x[87])&&CounterY==startY+(y[87]))|
						(CounterX==startX+(x[88])&&CounterY==startY+(y[88]))|
						(CounterX==startX+(x[89])&&CounterY==startY+(y[89]))|
						(CounterX==startX+(x[90])&&CounterY==startY+(y[90]))|
						(CounterX==startX+(x[91])&&CounterY==startY+(y[91]))|
						(CounterX==startX+(x[92])&&CounterY==startY+(y[92]))|
						(CounterX==startX+(x[93])&&CounterY==startY+(y[93]))|
						(CounterX==startX+(x[94])&&CounterY==startY+(y[94]))|
						(CounterX==startX+(x[95])&&CounterY==startY+(y[95]))|
						(CounterX==startX+(x[96])&&CounterY==startY+(y[96]))|
						(CounterX==startX+(x[97])&&CounterY==startY+(y[97]))|
						(CounterX==startX+(x[98])&&CounterY==startY+(y[98]))|
						(CounterX==startX+(x[99])&&CounterY==startY+(y[99]))|
						(CounterX==startX+(x[100])&&CounterY==startY+(y[100]))|
						(CounterX==startX+(x[101])&&CounterY==startY+(y[101]))|
						(CounterX==startX+(x[102])&&CounterY==startY+(y[102]))|
						(CounterX==startX+(x[103])&&CounterY==startY+(y[103]))|
						(CounterX==startX+(x[104])&&CounterY==startY+(y[104]))|
						(CounterX==startX+(x[105])&&CounterY==startY+(y[105]))|
						(CounterX==startX+(x[106])&&CounterY==startY+(y[106]))|
						(CounterX==startX+(x[107])&&CounterY==startY+(y[107]))|
						(CounterX==startX+(x[108])&&CounterY==startY+(y[108]))|
						(CounterX==startX+(x[109])&&CounterY==startY+(y[109]))|
						(CounterX==startX+(x[110])&&CounterY==startY+(y[110]))|
						(CounterX==startX+(x[111])&&CounterY==startY+(y[111]))|
						(CounterX==startX+(x[112])&&CounterY==startY+(y[112]))|
						(CounterX==startX+(x[113])&&CounterY==startY+(y[113]))|
						(CounterX==startX+(x[114])&&CounterY==startY+(y[114]))|
						(CounterX==startX+(x[115])&&CounterY==startY+(y[115]))|
						(CounterX==startX+(x[116])&&CounterY==startY+(y[116]))|
						(CounterX==startX+(x[117])&&CounterY==startY+(y[117]))|
						(CounterX==startX+(x[118])&&CounterY==startY+(y[118]))|
						(CounterX==startX+(x[119])&&CounterY==startY+(y[119]))|
						(CounterX==startX+(x[120])&&CounterY==startY+(y[120]))|
						(CounterX==startX+(x[121])&&CounterY==startY+(y[121]))|
						(CounterX==startX+(x[122])&&CounterY==startY+(y[122]))|
						(CounterX==startX+(x[123])&&CounterY==startY+(y[123]))|
						(CounterX==startX+(x[124])&&CounterY==startY+(y[124]))|
						(CounterX==startX+(x[125])&&CounterY==startY+(y[125]))|
						(CounterX==startX+(x[126])&&CounterY==startY+(y[126]))|
						(CounterX==startX+(x[127])&&CounterY==startY+(y[127]))|
						(CounterX==startX+(x[128])&&CounterY==startY+(y[128]))|
						(CounterX==startX+(x[129])&&CounterY==startY+(y[129]))|
						(CounterX==startX+(x[130])&&CounterY==startY+(y[130]))|
						(CounterX==startX+(x[131])&&CounterY==startY+(y[131]))|
						(CounterX==startX+(x[132])&&CounterY==startY+(y[132]))|
						(CounterX==startX+(x[133])&&CounterY==startY+(y[133]))|
						(CounterX==startX+(x[134])&&CounterY==startY+(y[134]))|
						(CounterX==startX+(x[135])&&CounterY==startY+(y[135]))|
						(CounterX==startX+(x[136])&&CounterY==startY+(y[136]))|
						(CounterX==startX+(x[137])&&CounterY==startY+(y[137]))|
						(CounterX==startX+(x[138])&&CounterY==startY+(y[138]))|
						(CounterX==startX+(x[139])&&CounterY==startY+(y[139]))|
						(CounterX==startX+(x[140])&&CounterY==startY+(y[140]))|
						(CounterX==startX+(x[141])&&CounterY==startY+(y[141]))|
						(CounterX==startX+(x[142])&&CounterY==startY+(y[142]))|
						(CounterX==startX+(x[143])&&CounterY==startY+(y[143]))|
						(CounterX==startX+(x[144])&&CounterY==startY+(y[144]))|
						(CounterX==startX+(x[145])&&CounterY==startY+(y[145]))|
						(CounterX==startX+(x[146])&&CounterY==startY+(y[146]))|
						(CounterX==startX+(x[147])&&CounterY==startY+(y[147]))|
						(CounterX==startX+(x[148])&&CounterY==startY+(y[148]))|
						(CounterX==startX+(x[149])&&CounterY==startY+(y[149]))|
						(CounterX==startX+(x[150])&&CounterY==startY+(y[150]))|
						(CounterX==startX+(x[151])&&CounterY==startY+(y[151]))|
						(CounterX==startX+(x[152])&&CounterY==startY+(y[152]))|
						(CounterX==startX+(x[153])&&CounterY==startY+(y[153]))|
						(CounterX==startX+(x[154])&&CounterY==startY+(y[154]))|
						(CounterX==startX+(x[155])&&CounterY==startY+(y[155]))|
						(CounterX==startX+(x[156])&&CounterY==startY+(y[156]))|
						(CounterX==startX+(x[157])&&CounterY==startY+(y[157]))|
						(CounterX==startX+(x[158])&&CounterY==startY+(y[158]))|
						(CounterX==startX+(x[159])&&CounterY==startY+(y[159]))|
						(CounterX==startX+(x[160])&&CounterY==startY+(y[160]))|
						(CounterX==startX+(x[161])&&CounterY==startY+(y[161]))|
						(CounterX==startX+(x[162])&&CounterY==startY+(y[162]))|
						(CounterX==startX+(x[163])&&CounterY==startY+(y[163]))|
						(CounterX==startX+(x[164])&&CounterY==startY+(y[164]))|
						(CounterX==startX+(x[165])&&CounterY==startY+(y[165]))|
						(CounterX==startX+(x[166])&&CounterY==startY+(y[166]))|
						(CounterX==startX+(x[167])&&CounterY==startY+(y[167]))|
						(CounterX==startX+(x[168])&&CounterY==startY+(y[168]))|
						(CounterX==startX+(x[169])&&CounterY==startY+(y[169]))|
						(CounterX==startX+(x[170])&&CounterY==startY+(y[170]))|
						(CounterX==startX+(x[171])&&CounterY==startY+(y[171]))|
						(CounterX==startX+(x[172])&&CounterY==startY+(y[172]))|
						(CounterX==startX+(x[173])&&CounterY==startY+(y[173]))|
						(CounterX==startX+(x[174])&&CounterY==startY+(y[174]))|
						(CounterX==startX+(x[175])&&CounterY==startY+(y[175]))|
						(CounterX==startX+(x[176])&&CounterY==startY+(y[176]))|
						(CounterX==startX+(x[177])&&CounterY==startY+(y[177]))|
						(CounterX==startX+(x[178])&&CounterY==startY+(y[178]))|
						(CounterX==startX+(x[179])&&CounterY==startY+(y[179]))|
						(CounterX==startX+(x[180])&&CounterY==startY+(y[180]))|
						(CounterX==startX+(x[181])&&CounterY==startY+(y[181]))|
						(CounterX==startX+(x[182])&&CounterY==startY+(y[182]))|
						(CounterX==startX+(x[183])&&CounterY==startY+(y[183]))|
						(CounterX==startX+(x[184])&&CounterY==startY+(y[184]))|
						(CounterX==startX+(x[185])&&CounterY==startY+(y[185]))|
						(CounterX==startX+(x[186])&&CounterY==startY+(y[186]))|
						(CounterX==startX+(x[187])&&CounterY==startY+(y[187]))|
						(CounterX==startX+(x[188])&&CounterY==startY+(y[188]))|
						(CounterX==startX+(x[189])&&CounterY==startY+(y[189]))|
						(CounterX==startX+(x[190])&&CounterY==startY+(y[190]))|
						(CounterX==startX+(x[191])&&CounterY==startY+(y[191]))|
						(CounterX==startX+(x[192])&&CounterY==startY+(y[192]))|
						(CounterX==startX+(x[193])&&CounterY==startY+(y[193]))|
						(CounterX==startX+(x[194])&&CounterY==startY+(y[194]))|
						(CounterX==startX+(x[195])&&CounterY==startY+(y[195]))|
						(CounterX==startX+(x[196])&&CounterY==startY+(y[196]))|
						(CounterX==startX+(x[197])&&CounterY==startY+(y[197]))|
						(CounterX==startX+(x[198])&&CounterY==startY+(y[198]))|
						(CounterX==startX+(x[199])&&CounterY==startY+(y[199]))|
						(CounterX==startX+(x[200])&&CounterY==startY+(y[200]))|
						(CounterX==startX+(x[201])&&CounterY==startY+(y[201]))|
						(CounterX==startX+(x[202])&&CounterY==startY+(y[202]))|
						(CounterX==startX+(x[203])&&CounterY==startY+(y[203]))|
						(CounterX==startX+(x[204])&&CounterY==startY+(y[204]))|
						(CounterX==startX+(x[205])&&CounterY==startY+(y[205]))|
						(CounterX==startX+(x[206])&&CounterY==startY+(y[206]))|
						(CounterX==startX+(x[207])&&CounterY==startY+(y[207]))|
						(CounterX==startX+(x[208])&&CounterY==startY+(y[208]))|
						(CounterX==startX+(x[209])&&CounterY==startY+(y[209]))|
						(CounterX==startX+(x[210])&&CounterY==startY+(y[210]))|
						(CounterX==startX+(x[211])&&CounterY==startY+(y[211]))|
						(CounterX==startX+(x[212])&&CounterY==startY+(y[212]))|
						(CounterX==startX+(x[213])&&CounterY==startY+(y[213]))|
						(CounterX==startX+(x[214])&&CounterY==startY+(y[214]))|
						(CounterX==startX+(x[215])&&CounterY==startY+(y[215]))|
						(CounterX==startX+(x[216])&&CounterY==startY+(y[216]))|
						(CounterX==startX+(x[217])&&CounterY==startY+(y[217]))|
						(CounterX==startX+(x[218])&&CounterY==startY+(y[218]))|
						(CounterX==startX+(x[219])&&CounterY==startY+(y[219]))|
						(CounterX==startX+(x[220])&&CounterY==startY+(y[220]))|
						(CounterX==startX+(x[221])&&CounterY==startY+(y[221]))|
						(CounterX==startX+(x[222])&&CounterY==startY+(y[222]))|
						(CounterX==startX+(x[223])&&CounterY==startY+(y[223]))|
						(CounterX==startX+(x[224])&&CounterY==startY+(y[224]))|
						(CounterX==startX+(x[225])&&CounterY==startY+(y[225]))|
						(CounterX==startX+(x[226])&&CounterY==startY+(y[226]))|
						(CounterX==startX+(x[227])&&CounterY==startY+(y[227]))|
						(CounterX==startX+(x[228])&&CounterY==startY+(y[228]))|
						(CounterX==startX+(x[229])&&CounterY==startY+(y[229]))|
						(CounterX==startX+(x[230])&&CounterY==startY+(y[230]))|
						(CounterX==startX+(x[231])&&CounterY==startY+(y[231]))|
						(CounterX==startX+(x[232])&&CounterY==startY+(y[232]))|
						(CounterX==startX+(x[233])&&CounterY==startY+(y[233]))|
						(CounterX==startX+(x[234])&&CounterY==startY+(y[234]))|
						(CounterX==startX+(x[235])&&CounterY==startY+(y[235]))|
						(CounterX==startX+(x[236])&&CounterY==startY+(y[236]))|
						(CounterX==startX+(x[237])&&CounterY==startY+(y[237]))|
						(CounterX==startX+(x[238])&&CounterY==startY+(y[238]))|
						(CounterX==startX+(x[239])&&CounterY==startY+(y[239]))|
						(CounterX==startX+(x[240])&&CounterY==startY+(y[240]))|
						(CounterX==startX+(x[241])&&CounterY==startY+(y[241]))|
						(CounterX==startX+(x[242])&&CounterY==startY+(y[242]))|
						(CounterX==startX+(x[243])&&CounterY==startY+(y[243]))|
						(CounterX==startX+(x[244])&&CounterY==startY+(y[244]))|
						(CounterX==startX+(x[245])&&CounterY==startY+(y[245]))|
						(CounterX==startX+(x[246])&&CounterY==startY+(y[246]))|
						(CounterX==startX+(x[247])&&CounterY==startY+(y[247]))|
						(CounterX==startX+(x[248])&&CounterY==startY+(y[248]))|
						(CounterX==startX+(x[249])&&CounterY==startY+(y[249]))|
						(CounterX==startX+(x[250])&&CounterY==startY+(y[250]))|
						(CounterX==startX+(x[251])&&CounterY==startY+(y[251]))|
						(CounterX==startX+(x[252])&&CounterY==startY+(y[252]))|
						(CounterX==startX+(x[253])&&CounterY==startY+(y[253]))|
						(CounterX==startX+(x[254])&&CounterY==startY+(y[254]))|
						(CounterX==startX+(x[255])&&CounterY==startY+(y[255]))|
						(CounterX==startX+(x[256])&&CounterY==startY+(y[256]))|
						(CounterX==startX+(x[257])&&CounterY==startY+(y[257]))|
						(CounterX==startX+(x[258])&&CounterY==startY+(y[258]))|
						(CounterX==startX+(x[259])&&CounterY==startY+(y[259]))|
						(CounterX==startX+(x[260])&&CounterY==startY+(y[260]))|
						(CounterX==startX+(x[261])&&CounterY==startY+(y[261]))|
						(CounterX==startX+(x[262])&&CounterY==startY+(y[262]))|
						(CounterX==startX+(x[263])&&CounterY==startY+(y[263]))|
						(CounterX==startX+(x[264])&&CounterY==startY+(y[264]))|
						(CounterX==startX+(x[265])&&CounterY==startY+(y[265]))|
						(CounterX==startX+(x[266])&&CounterY==startY+(y[266]))|
						(CounterX==startX+(x[267])&&CounterY==startY+(y[267]))|
						(CounterX==startX+(x[268])&&CounterY==startY+(y[268]))|
						(CounterX==startX+(x[269])&&CounterY==startY+(y[269]))|
						(CounterX==startX+(x[270])&&CounterY==startY+(y[270]))|
						(CounterX==startX+(x[271])&&CounterY==startY+(y[271]))|
						(CounterX==startX+(x[272])&&CounterY==startY+(y[272]))|
						(CounterX==startX+(x[273])&&CounterY==startY+(y[273]))|
						(CounterX==startX+(x[274])&&CounterY==startY+(y[274]))|
						(CounterX==startX+(x[275])&&CounterY==startY+(y[275]))|
						(CounterX==startX+(x[276])&&CounterY==startY+(y[276]))|
						(CounterX==startX+(x[277])&&CounterY==startY+(y[277]))|
						(CounterX==startX+(x[278])&&CounterY==startY+(y[278]))|
						(CounterX==startX+(x[279])&&CounterY==startY+(y[279]))|
						(CounterX==startX+(x[280])&&CounterY==startY+(y[280]))|
						(CounterX==startX+(x[281])&&CounterY==startY+(y[281]))|
						(CounterX==startX+(x[282])&&CounterY==startY+(y[282]))|
						(CounterX==startX+(x[283])&&CounterY==startY+(y[283]))|
						(CounterX==startX+(x[284])&&CounterY==startY+(y[284]))|
						(CounterX==startX+(x[285])&&CounterY==startY+(y[285]))|
						(CounterX==startX+(x[286])&&CounterY==startY+(y[286]))|
						(CounterX==startX+(x[287])&&CounterY==startY+(y[287]))|
						(CounterX==startX+(x[288])&&CounterY==startY+(y[288]))|
						(CounterX==startX+(x[289])&&CounterY==startY+(y[289]))|
						(CounterX==startX+(x[290])&&CounterY==startY+(y[290]))|
						(CounterX==startX+(x[291])&&CounterY==startY+(y[291]))|
						(CounterX==startX+(x[292])&&CounterY==startY+(y[292]))|
						(CounterX==startX+(x[293])&&CounterY==startY+(y[293]))|
						(CounterX==startX+(x[294])&&CounterY==startY+(y[294]))|
						(CounterX==startX+(x[295])&&CounterY==startY+(y[295]))|
						(CounterX==startX+(x[296])&&CounterY==startY+(y[296]))|
						(CounterX==startX+(x[297])&&CounterY==startY+(y[297]))|
						(CounterX==startX+(x[298])&&CounterY==startY+(y[298]))|
						(CounterX==startX+(x[299])&&CounterY==startY+(y[299]));	
endmodule

module draw(x,y,CounterX,CounterY, character, color);

	input [9:0]x;
	input [8:0]y;
	input [4:0]character;
	input [9:0]CounterX;
	input [8:0]CounterY;
	output color;
	reg color;
	
	parameter X = 5'd10,
				 Y = 5'd11,
				 PLUS = 5'd12,
				 MINUS = 5'd13,
				 EQUAL = 5'd14,
				 PLANE = 5'd15,
				 GRAPH = 5'd16;
	
	
	always @(*)
	begin
		case(character)
			5'd0: color = (CounterX==x+4&&CounterY>=y&&CounterY<=y+6)|
								(CounterX==x&&CounterY>=y&&CounterY<=y+6)|
								(CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+6));
			5'd1: color = (CounterX>=x&&CounterX<=x+2&&CounterY==y)|
								(CounterX==x+2&&CounterY>=y&&CounterY<=y+6)|
								(CounterX>=x&&CounterX<=x+4&&CounterY==y+6);
			5'd2: color = (CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+3||CounterY==y+6))|
								(CounterX==x&&CounterY>=y+3&&CounterY<=y+6)|
								(CounterX==x+4&&CounterY>=y&&CounterY<=y+3);
			5'd3: color = (CounterX>=x&&CounterX<=x+4&&(CounterY==y|CounterY==y+3|CounterY==y+6))|
								(CounterX==x+4&&CounterY>=y&&CounterY<=y+6);
			5'd4: color = (CounterX==x+4&&CounterY>=y&&CounterY<=y+6)|
								(CounterX>=x&&CounterX<=x+4&&CounterY==y+3)|
								(CounterX==x&&CounterY>=y&&CounterY<=y+3);
			5'd5: color = (CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+3||CounterY==y+6))|
								(CounterX==x+4&&CounterY>=y+3&&CounterY<=y+6)|
								(CounterX==x&&CounterY>=y&&CounterY<=y+3);
			5'd6: color = (CounterX==x&&CounterY>=y&&CounterY<=y+6)|
								(CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+3||CounterY==y+6))|
								(CounterX==x+4&&CounterY>=y+3&&CounterY<=y+6);
			5'd7: color = (CounterX==x+4&&CounterY>=y&&CounterY<=y+6)|
								(CounterX>=x&&CounterX<=x+4&&CounterY==y);
			5'd8: color = (CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+3||CounterY==y+6))|
								(CounterX==x+4&&CounterY>=y&&CounterY<=y+6)|
								(CounterX==x&&CounterY>=y&&CounterY<=y+6);								
			5'd9: color = (CounterX==x+4&&CounterY>=y&&CounterY<=y+6)|
								(CounterX==x&&CounterY>=y&&CounterY<=y+3)|
								(CounterX>=x&&CounterX<=x+4&&(CounterY==y||CounterY==y+3||CounterY==y+6));
			X: color = (((CounterX+1-x)==(CounterY-y))&&(CounterX>=x)&&(CounterX<=x+4))|
							(((5-(CounterX-x))==(CounterY-y))&&CounterX>=x&&CounterX<=x+4)|
							(((CounterX==x)|(CounterX==x+4))&&(CounterY==y|CounterY==y+6));
			Y: color = (((((CounterX+1-x)==(CounterY-y))&&(CounterY>=y+1)&&(CounterY<=y+3))|
							(((5-(CounterX-x))==(CounterY-y))&&(CounterY>=y+1)&&(CounterY<=y+3))|
							(((CounterX==x)|(CounterX==x+4))&&(CounterY==y))|
							(CounterX==x+2&&CounterY>=y+4&&CounterY<=y+6)));
			PLUS: color = (CounterX==x+2&&CounterY>=y+1&&CounterY<=y+5)|
								(CounterY==y+3&&CounterX>=x&&CounterX<=x+4);
			MINUS: color = CounterY==y+3&&CounterX>=x&&CounterX<=x+4;
			EQUAL: color = (CounterX>=x&&CounterX<=x+5&&(CounterY==y+2||CounterY==y+4));
			PLANE: color = (CounterX==x+149&&CounterY>=y&&CounterY<=y+299)|
								(CounterY==y+149&&CounterX>=x&&CounterX<=x+299);
			//GRAPH: color = CounterX==149+10*x&&CounterY==149-10*y;
			default color = 1'b1;
		endcase
	end
						
endmodule